{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:02:16, Iteration: 1000, Train Loss: 3.1390e+00, c1: 5.2197e-03, c2: 8.0355e-01, d1: 4.5935e-01, d2: 0.0000e+00, l1_reg: 2.9378e+02, l2_reg: 4.1204e+01\n",
      "2020/09/09, 10:02:41, Iteration: 2000, Train Loss: 2.6489e+00, c1: 7.5462e-03, c2: 3.6737e-01, d1: 4.4813e-01, d2: 0.0000e+00, l1_reg: 2.9207e+02, l2_reg: 4.1299e+01\n",
      "2020/09/09, 10:03:08, Iteration: 3000, Train Loss: 2.4405e+00, c1: 1.0484e-02, c2: 1.8947e-01, d1: 4.4143e-01, d2: 0.0000e+00, l1_reg: 2.9169e+02, l2_reg: 4.2261e+01\n",
      "2020/09/09, 10:03:34, Iteration: 4000, Train Loss: 2.3146e+00, c1: 2.2310e-02, c2: 1.7437e-01, d1: 4.1681e-01, d2: 0.0000e+00, l1_reg: 2.9364e+02, l2_reg: 4.5331e+01\n",
      "2020/09/09, 10:04:01, Iteration: 5000, Train Loss: 1.8758e+00, c1: 6.4569e-02, c2: 8.0252e-01, d1: 1.9437e-01, d2: 0.0000e+00, l1_reg: 3.1108e+02, l2_reg: 5.7360e+01\n",
      "2020/09/09, 10:04:27, Iteration: 6000, Train Loss: 9.3485e-01, c1: 1.5484e-02, c2: 6.0623e-01, d1: 5.4694e-02, d2: 0.0000e+00, l1_reg: 3.2586e+02, l2_reg: 7.0795e+01\n",
      "2020/09/09, 10:04:53, Iteration: 7000, Train Loss: 7.2931e-01, c1: 2.1941e-02, c2: 4.4634e-01, d1: 4.4090e-02, d2: 0.0000e+00, l1_reg: 3.3008e+02, l2_reg: 7.5658e+01\n",
      "2020/09/09, 10:05:20, Iteration: 8000, Train Loss: 6.1256e-01, c1: 1.3871e-02, c2: 3.6518e-01, d1: 3.8451e-02, d2: 0.0000e+00, l1_reg: 3.3289e+02, l2_reg: 7.9702e+01\n",
      "2020/09/09, 10:05:46, Iteration: 9000, Train Loss: 6.1052e-01, c1: 1.4190e-02, c2: 3.8813e-01, d1: 3.3258e-02, d2: 0.0000e+00, l1_reg: 3.3541e+02, l2_reg: 8.3757e+01\n",
      "2020/09/09, 10:06:13, Iteration: 10000, Train Loss: 5.0566e-01, c1: 1.7212e-02, c2: 2.9696e-01, d1: 2.9830e-02, d2: 0.0000e+00, l1_reg: 3.3681e+02, l2_reg: 8.6564e+01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray\n",
      "  return array(a, dtype, copy=False, order=order)\n"
     ]
    }
   ],
   "source": [
    "import jax\n",
    "import jax.numpy as jnp\n",
    "\n",
    "import os, sys\n",
    "sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(\"./\")))))\n",
    "\n",
    "from training import Agent\n",
    "from loss import params, loss_fn, evaluate_fn\n",
    "from data import generate_dataset, generate_batch_fn\n",
    "\n",
    "import config\n",
    "config.n_data = {\n",
    "    \"i\": 100,\n",
    "    \"b\": 100,\n",
    "    \"cx\": 1001,\n",
    "    \"ct\": 1001,\n",
    "    \"dx\": 100,\n",
    "    \"dt\": 602,\n",
    "}\n",
    "config.batch_size = {\n",
    "    \"dirichlet\": (config.n_data[\"i\"]+2*config.n_data[\"b\"]+config.n_data[\"dx\"]*config.n_data[\"dt\"]) // 20,\n",
    "    \"collocation\": (config.n_data[\"dx\"]*config.n_data[\"dt\"]+config.n_data[\"cx\"]*config.n_data[\"ct\"]) // 20,\n",
    "}\n",
    "config.iterations = 10000\n",
    "config.print_every = 1000\n",
    "config.lr = 1e-3\n",
    "config.weights = {\n",
    "\t\"c1\": 1.0,\n",
    "\t\"c2\": 1.0,\n",
    "\t\"d1\": 5.0,\n",
    "\t\"d2\": 1.0,\n",
    "\t\"l1\": 1e-4,\n",
    "\t\"l2\": 1e-4,\n",
    "}\n",
    "\n",
    "datasets = generate_dataset(config.n_data[\"i\"], config.n_data[\"b\"], config.n_data[\"cx\"], config.n_data[\"ct\"], config.n_data[\"dx\"], config.n_data[\"dt\"])\n",
    "batch_fn, evaluate_batch_fn = generate_batch_fn(config.key, config.batch_size, *datasets, config.weights)\n",
    "\n",
    "agent = Agent(params, loss_fn, evaluate_fn, \"models/{}\".format(config.NAME))\n",
    "agent.compile(config.optimizer, config.lr)\n",
    "agent.train(config.iterations, batch_fn, evaluate_batch_fn, config.print_every, config.save_every, config.loss_names, config.log_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:07:58, Iteration: 11000, Train Loss: 4.9917e-01, c1: 1.6753e-02, c2: 3.0805e-01, d1: 2.6343e-02, d2: 0.0000e+00, l1_reg: 3.3781e+02, l2_reg: 8.8810e+01\n",
      "2020/09/09, 10:08:24, Iteration: 12000, Train Loss: 4.8622e-01, c1: 1.2089e-02, c2: 3.1309e-01, d1: 2.3578e-02, d2: 0.0000e+00, l1_reg: 3.3974e+02, l2_reg: 9.1780e+01\n",
      "2020/09/09, 10:08:50, Iteration: 13000, Train Loss: 3.7525e-01, c1: 1.1009e-02, c2: 2.1707e-01, d1: 2.0703e-02, d2: 0.0000e+00, l1_reg: 3.4149e+02, l2_reg: 9.5026e+01\n",
      "2020/09/09, 10:09:17, Iteration: 14000, Train Loss: 3.2458e-01, c1: 1.2102e-02, c2: 1.7005e-01, d1: 1.9685e-02, d2: 0.0000e+00, l1_reg: 3.4246e+02, l2_reg: 9.7516e+01\n",
      "2020/09/09, 10:09:43, Iteration: 15000, Train Loss: 3.2177e-01, c1: 1.2737e-02, c2: 1.6936e-01, d1: 1.9074e-02, d2: 0.0000e+00, l1_reg: 3.4332e+02, l2_reg: 9.9753e+01\n",
      "2020/09/09, 10:10:10, Iteration: 16000, Train Loss: 2.7299e-01, c1: 1.1962e-02, c2: 1.2564e-01, d1: 1.8183e-02, d2: 0.0000e+00, l1_reg: 3.4338e+02, l2_reg: 1.0131e+02\n",
      "2020/09/09, 10:10:36, Iteration: 17000, Train Loss: 2.3886e-01, c1: 1.0824e-02, c2: 9.7493e-02, d1: 1.7211e-02, d2: 0.0000e+00, l1_reg: 3.4282e+02, l2_reg: 1.0205e+02\n",
      "2020/09/09, 10:11:02, Iteration: 18000, Train Loss: 1.9751e-01, c1: 1.1147e-02, c2: 6.0673e-02, d1: 1.6250e-02, d2: 0.0000e+00, l1_reg: 3.4212e+02, l2_reg: 1.0231e+02\n",
      "2020/09/09, 10:11:29, Iteration: 19000, Train Loss: 1.8376e-01, c1: 1.0620e-02, c2: 5.2225e-02, d1: 1.5329e-02, d2: 0.0000e+00, l1_reg: 3.4081e+02, l2_reg: 1.0193e+02\n",
      "2020/09/09, 10:11:55, Iteration: 20000, Train Loss: 1.8000e-01, c1: 2.3819e-02, c2: 3.8160e-02, d1: 1.4789e-02, d2: 0.0000e+00, l1_reg: 3.3927e+02, l2_reg: 1.0151e+02\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray\n",
      "  return array(a, dtype, copy=False, order=order)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:12:22, Iteration: 21000, Train Loss: 1.7736e-01, c1: 1.2646e-02, c2: 5.0208e-02, d1: 1.4129e-02, d2: 0.0000e+00, l1_reg: 3.3761e+02, l2_reg: 1.0100e+02\n",
      "2020/09/09, 10:12:48, Iteration: 22000, Train Loss: 1.5602e-01, c1: 5.8470e-03, c2: 3.7783e-02, d1: 1.3757e-02, d2: 0.0000e+00, l1_reg: 3.3576e+02, l2_reg: 1.0028e+02\n",
      "2020/09/09, 10:13:14, Iteration: 23000, Train Loss: 1.7453e-01, c1: 1.4385e-02, c2: 4.5401e-02, d1: 1.4269e-02, d2: 0.0000e+00, l1_reg: 3.3400e+02, l2_reg: 9.9962e+01\n",
      "2020/09/09, 10:13:41, Iteration: 24000, Train Loss: 1.5276e-01, c1: 1.0455e-02, c2: 3.2529e-02, d1: 1.3324e-02, d2: 0.0000e+00, l1_reg: 3.3186e+02, l2_reg: 9.9663e+01\n",
      "2020/09/09, 10:14:07, Iteration: 25000, Train Loss: 1.4593e-01, c1: 5.9903e-03, c2: 3.0231e-02, d1: 1.3372e-02, d2: 0.0000e+00, l1_reg: 3.2931e+02, l2_reg: 9.9161e+01\n",
      "2020/09/09, 10:14:33, Iteration: 26000, Train Loss: 1.5099e-01, c1: 7.6665e-03, c2: 3.0086e-02, d1: 1.4145e-02, d2: 0.0000e+00, l1_reg: 3.2649e+02, l2_reg: 9.8619e+01\n",
      "2020/09/09, 10:15:00, Iteration: 27000, Train Loss: 1.4540e-01, c1: 1.4709e-02, c2: 2.1585e-02, d1: 1.3390e-02, d2: 0.0000e+00, l1_reg: 3.2349e+02, l2_reg: 9.8069e+01\n",
      "2020/09/09, 10:15:26, Iteration: 28000, Train Loss: 1.5642e-01, c1: 1.0798e-02, c2: 3.3600e-02, d1: 1.4046e-02, d2: 0.0000e+00, l1_reg: 3.2037e+02, l2_reg: 9.7509e+01\n",
      "2020/09/09, 10:15:52, Iteration: 29000, Train Loss: 1.4252e-01, c1: 1.2892e-02, c2: 2.0840e-02, d1: 1.3484e-02, d2: 0.0000e+00, l1_reg: 3.1692e+02, l2_reg: 9.6811e+01\n",
      "2020/09/09, 10:16:19, Iteration: 30000, Train Loss: 1.4278e-01, c1: 9.7082e-03, c2: 2.4195e-02, d1: 1.3587e-02, d2: 0.0000e+00, l1_reg: 3.1334e+02, l2_reg: 9.6117e+01\n",
      "2020/09/09, 10:16:45, Iteration: 31000, Train Loss: 1.3203e-01, c1: 1.1676e-02, c2: 1.4221e-02, d1: 1.3124e-02, d2: 0.0000e+00, l1_reg: 3.0966e+02, l2_reg: 9.5458e+01\n",
      "2020/09/09, 10:17:11, Iteration: 32000, Train Loss: 1.3885e-01, c1: 7.6093e-03, c2: 2.5680e-02, d1: 1.3107e-02, d2: 0.0000e+00, l1_reg: 3.0569e+02, l2_reg: 9.4612e+01\n",
      "2020/09/09, 10:17:38, Iteration: 33000, Train Loss: 1.3312e-01, c1: 1.0850e-02, c2: 1.6630e-02, d1: 1.3233e-02, d2: 0.0000e+00, l1_reg: 3.0128e+02, l2_reg: 9.3523e+01\n",
      "2020/09/09, 10:18:04, Iteration: 34000, Train Loss: 1.2198e-01, c1: 4.6669e-03, c2: 1.3505e-02, d1: 1.2982e-02, d2: 0.0000e+00, l1_reg: 2.9655e+02, l2_reg: 9.2445e+01\n",
      "2020/09/09, 10:18:30, Iteration: 35000, Train Loss: 1.2863e-01, c1: 3.8984e-03, c2: 2.0993e-02, d1: 1.3081e-02, d2: 0.0000e+00, l1_reg: 2.9179e+02, l2_reg: 9.1518e+01\n",
      "2020/09/09, 10:18:57, Iteration: 36000, Train Loss: 1.3059e-01, c1: 5.2769e-03, c2: 2.1680e-02, d1: 1.3180e-02, d2: 0.0000e+00, l1_reg: 2.8694e+02, l2_reg: 9.0353e+01\n",
      "2020/09/09, 10:19:23, Iteration: 37000, Train Loss: 1.3723e-01, c1: 8.7144e-03, c2: 2.1695e-02, d1: 1.3935e-02, d2: 0.0000e+00, l1_reg: 2.8214e+02, l2_reg: 8.9260e+01\n",
      "2020/09/09, 10:19:49, Iteration: 38000, Train Loss: 1.2793e-01, c1: 8.4520e-03, c2: 1.5963e-02, d1: 1.3390e-02, d2: 0.0000e+00, l1_reg: 2.7748e+02, l2_reg: 8.8197e+01\n",
      "2020/09/09, 10:20:16, Iteration: 39000, Train Loss: 1.3105e-01, c1: 7.3656e-03, c2: 2.0915e-02, d1: 1.3357e-02, d2: 0.0000e+00, l1_reg: 2.7267e+02, l2_reg: 8.7186e+01\n",
      "2020/09/09, 10:20:42, Iteration: 40000, Train Loss: 1.2744e-01, c1: 5.8567e-03, c2: 1.7085e-02, d1: 1.3820e-02, d2: 0.0000e+00, l1_reg: 2.6785e+02, l2_reg: 8.6146e+01\n",
      "2020/09/09, 10:21:08, Iteration: 41000, Train Loss: 1.1629e-01, c1: 3.6902e-03, c2: 1.3984e-02, d1: 1.2759e-02, d2: 0.0000e+00, l1_reg: 2.6312e+02, l2_reg: 8.5141e+01\n",
      "2020/09/09, 10:21:34, Iteration: 42000, Train Loss: 1.1994e-01, c1: 5.7459e-03, c2: 1.2145e-02, d1: 1.3560e-02, d2: 0.0000e+00, l1_reg: 2.5849e+02, l2_reg: 8.4064e+01\n",
      "2020/09/09, 10:22:01, Iteration: 43000, Train Loss: 1.1448e-01, c1: 3.8999e-03, c2: 1.2548e-02, d1: 1.2865e-02, d2: 0.0000e+00, l1_reg: 2.5396e+02, l2_reg: 8.3144e+01\n",
      "2020/09/09, 10:22:27, Iteration: 44000, Train Loss: 1.1731e-01, c1: 5.9063e-03, c2: 1.0214e-02, d1: 1.3608e-02, d2: 0.0000e+00, l1_reg: 2.4938e+02, l2_reg: 8.2186e+01\n",
      "2020/09/09, 10:22:53, Iteration: 45000, Train Loss: 1.1765e-01, c1: 4.4783e-03, c2: 1.0620e-02, d1: 1.3991e-02, d2: 0.0000e+00, l1_reg: 2.4479e+02, l2_reg: 8.1204e+01\n",
      "2020/09/09, 10:23:20, Iteration: 46000, Train Loss: 1.2050e-01, c1: 7.7284e-03, c2: 1.4949e-02, d1: 1.3149e-02, d2: 0.0000e+00, l1_reg: 2.4040e+02, l2_reg: 8.0342e+01\n",
      "2020/09/09, 10:23:46, Iteration: 47000, Train Loss: 1.1701e-01, c1: 6.6109e-03, c2: 1.1939e-02, d1: 1.3389e-02, d2: 0.0000e+00, l1_reg: 2.3571e+02, l2_reg: 7.9425e+01\n",
      "2020/09/09, 10:24:12, Iteration: 48000, Train Loss: 1.1050e-01, c1: 3.2705e-03, c2: 1.1956e-02, d1: 1.2854e-02, d2: 0.0000e+00, l1_reg: 2.3145e+02, l2_reg: 7.8593e+01\n",
      "2020/09/09, 10:24:38, Iteration: 49000, Train Loss: 1.1026e-01, c1: 5.9195e-03, c2: 9.8465e-03, d1: 1.2799e-02, d2: 0.0000e+00, l1_reg: 2.2730e+02, l2_reg: 7.7689e+01\n",
      "2020/09/09, 10:25:05, Iteration: 50000, Train Loss: 1.1307e-01, c1: 7.5715e-03, c2: 1.2134e-02, d1: 1.2670e-02, d2: 0.0000e+00, l1_reg: 2.2323e+02, l2_reg: 7.6888e+01\n"
     ]
    }
   ],
   "source": [
    "config.iterations = 40000\n",
    "agent.train(config.iterations, batch_fn, evaluate_batch_fn, config.print_every, config.save_every, config.loss_names, config.log_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:27:36, Iteration: 51000, Train Loss: 9.8852e-03, c1: 2.0331e-03, c2: 4.0134e-03, d1: 1.2581e-02, d2: 0.0000e+00, l1_reg: 2.2246e+02, l2_reg: 7.6542e+01\n",
      "2020/09/09, 10:28:02, Iteration: 52000, Train Loss: 9.8150e-03, c1: 1.9002e-03, c2: 3.7720e-03, d1: 1.2547e-02, d2: 0.0000e+00, l1_reg: 2.2137e+02, l2_reg: 7.6051e+01\n",
      "2020/09/09, 10:28:27, Iteration: 53000, Train Loss: 1.0223e-02, c1: 1.9037e-03, c2: 7.6183e-03, d1: 1.2633e-02, d2: 0.0000e+00, l1_reg: 2.1994e+02, l2_reg: 7.5541e+01\n",
      "2020/09/09, 10:28:54, Iteration: 54000, Train Loss: 1.0395e-02, c1: 3.8087e-03, c2: 7.8874e-03, d1: 1.2586e-02, d2: 0.0000e+00, l1_reg: 2.1802e+02, l2_reg: 7.5173e+01\n",
      "2020/09/09, 10:29:20, Iteration: 55000, Train Loss: 1.0603e-02, c1: 2.3708e-03, c2: 1.1634e-02, d1: 1.2596e-02, d2: 0.0000e+00, l1_reg: 2.1568e+02, l2_reg: 7.4739e+01\n",
      "2020/09/09, 10:29:47, Iteration: 56000, Train Loss: 1.0870e-02, c1: 5.6451e-03, c2: 9.6599e-03, d1: 1.2938e-02, d2: 0.0000e+00, l1_reg: 2.1277e+02, l2_reg: 7.4227e+01\n",
      "2020/09/09, 10:30:13, Iteration: 57000, Train Loss: 1.0885e-02, c1: 4.4849e-03, c2: 1.1796e-02, d1: 1.2842e-02, d2: 0.0000e+00, l1_reg: 2.0984e+02, l2_reg: 7.3769e+01\n",
      "2020/09/09, 10:30:40, Iteration: 58000, Train Loss: 1.0877e-02, c1: 4.0368e-03, c2: 1.1463e-02, d1: 1.3054e-02, d2: 0.0000e+00, l1_reg: 2.0678e+02, l2_reg: 7.3254e+01\n",
      "2020/09/09, 10:31:06, Iteration: 59000, Train Loss: 1.1390e-02, c1: 4.6364e-03, c2: 1.6302e-02, d1: 1.3063e-02, d2: 0.0000e+00, l1_reg: 2.0384e+02, l2_reg: 7.2696e+01\n",
      "2020/09/09, 10:31:32, Iteration: 60000, Train Loss: 1.0993e-02, c1: 3.3966e-03, c2: 1.5912e-02, d1: 1.2668e-02, d2: 0.0000e+00, l1_reg: 2.0062e+02, l2_reg: 7.2197e+01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray\n",
      "  return array(a, dtype, copy=False, order=order)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:31:59, Iteration: 61000, Train Loss: 1.0809e-02, c1: 4.5512e-03, c2: 1.3564e-02, d1: 1.2609e-02, d2: 0.0000e+00, l1_reg: 1.9762e+02, l2_reg: 7.1629e+01\n",
      "2020/09/09, 10:32:25, Iteration: 62000, Train Loss: 1.0398e-02, c1: 5.0950e-03, c2: 9.1822e-03, d1: 1.2629e-02, d2: 0.0000e+00, l1_reg: 1.9450e+02, l2_reg: 7.1085e+01\n",
      "2020/09/09, 10:32:51, Iteration: 63000, Train Loss: 1.0969e-02, c1: 3.7176e-03, c2: 1.4738e-02, d1: 1.3012e-02, d2: 0.0000e+00, l1_reg: 1.9127e+02, l2_reg: 7.0478e+01\n",
      "2020/09/09, 10:33:18, Iteration: 64000, Train Loss: 1.0076e-02, c1: 3.5862e-03, c2: 8.2971e-03, d1: 1.2607e-02, d2: 0.0000e+00, l1_reg: 1.8843e+02, l2_reg: 7.0000e+01\n",
      "2020/09/09, 10:33:44, Iteration: 65000, Train Loss: 1.0312e-02, c1: 4.4785e-03, c2: 9.3265e-03, d1: 1.2763e-02, d2: 0.0000e+00, l1_reg: 1.8551e+02, l2_reg: 6.9479e+01\n",
      "2020/09/09, 10:34:10, Iteration: 66000, Train Loss: 1.1050e-02, c1: 4.2626e-03, c2: 1.4978e-02, d1: 1.3220e-02, d2: 0.0000e+00, l1_reg: 1.8259e+02, l2_reg: 6.8996e+01\n",
      "2020/09/09, 10:34:37, Iteration: 67000, Train Loss: 1.0779e-02, c1: 3.7753e-03, c2: 1.2187e-02, d1: 1.3393e-02, d2: 0.0000e+00, l1_reg: 1.8006e+02, l2_reg: 6.8556e+01\n",
      "2020/09/09, 10:35:03, Iteration: 68000, Train Loss: 1.0495e-02, c1: 5.2689e-03, c2: 1.1243e-02, d1: 1.2775e-02, d2: 0.0000e+00, l1_reg: 1.7757e+02, l2_reg: 6.8058e+01\n",
      "2020/09/09, 10:35:29, Iteration: 69000, Train Loss: 1.0216e-02, c1: 2.0997e-03, c2: 1.0958e-02, d1: 1.2972e-02, d2: 0.0000e+00, l1_reg: 1.7482e+02, l2_reg: 6.7610e+01\n",
      "2020/09/09, 10:35:55, Iteration: 70000, Train Loss: 1.0286e-02, c1: 3.4822e-03, c2: 9.9817e-03, d1: 1.3088e-02, d2: 0.0000e+00, l1_reg: 1.7241e+02, l2_reg: 6.7145e+01\n",
      "2020/09/09, 10:36:22, Iteration: 71000, Train Loss: 1.0541e-02, c1: 4.5103e-03, c2: 1.1081e-02, d1: 1.3228e-02, d2: 0.0000e+00, l1_reg: 1.7005e+02, l2_reg: 6.6717e+01\n",
      "2020/09/09, 10:36:48, Iteration: 72000, Train Loss: 1.0672e-02, c1: 5.2885e-03, c2: 1.3640e-02, d1: 1.2876e-02, d2: 0.0000e+00, l1_reg: 1.6776e+02, l2_reg: 6.6297e+01\n",
      "2020/09/09, 10:37:14, Iteration: 73000, Train Loss: 1.0696e-02, c1: 4.3388e-03, c2: 1.3973e-02, d1: 1.3101e-02, d2: 0.0000e+00, l1_reg: 1.6556e+02, l2_reg: 6.5871e+01\n",
      "2020/09/09, 10:37:41, Iteration: 74000, Train Loss: 1.0280e-02, c1: 3.4735e-03, c2: 1.2577e-02, d1: 1.2773e-02, d2: 0.0000e+00, l1_reg: 1.6340e+02, l2_reg: 6.5478e+01\n",
      "2020/09/09, 10:38:07, Iteration: 75000, Train Loss: 1.0471e-02, c1: 4.2040e-03, c2: 1.2062e-02, d1: 1.3166e-02, d2: 0.0000e+00, l1_reg: 1.6110e+02, l2_reg: 6.5095e+01\n",
      "2020/09/09, 10:38:33, Iteration: 76000, Train Loss: 9.7807e-03, c1: 2.8120e-03, c2: 9.9141e-03, d1: 1.2537e-02, d2: 0.0000e+00, l1_reg: 1.5919e+02, l2_reg: 6.4747e+01\n",
      "2020/09/09, 10:39:00, Iteration: 77000, Train Loss: 9.9974e-03, c1: 1.9630e-03, c2: 1.1991e-02, d1: 1.2771e-02, d2: 0.0000e+00, l1_reg: 1.5726e+02, l2_reg: 6.4381e+01\n",
      "2020/09/09, 10:39:26, Iteration: 78000, Train Loss: 1.0462e-02, c1: 5.6397e-03, c2: 1.3310e-02, d1: 1.2750e-02, d2: 0.0000e+00, l1_reg: 1.5520e+02, l2_reg: 6.4032e+01\n",
      "2020/09/09, 10:39:52, Iteration: 79000, Train Loss: 9.8586e-03, c1: 3.8588e-03, c2: 1.0104e-02, d1: 1.2580e-02, d2: 0.0000e+00, l1_reg: 1.5350e+02, l2_reg: 6.3731e+01\n",
      "2020/09/09, 10:40:19, Iteration: 80000, Train Loss: 9.9882e-03, c1: 3.5905e-03, c2: 9.8388e-03, d1: 1.2988e-02, d2: 0.0000e+00, l1_reg: 1.5166e+02, l2_reg: 6.3450e+01\n",
      "2020/09/09, 10:40:45, Iteration: 81000, Train Loss: 1.0032e-02, c1: 1.6572e-03, c2: 9.8031e-03, d1: 1.3507e-02, d2: 0.0000e+00, l1_reg: 1.5012e+02, l2_reg: 6.3142e+01\n",
      "2020/09/09, 10:41:11, Iteration: 82000, Train Loss: 9.7828e-03, c1: 3.3858e-03, c2: 9.1996e-03, d1: 1.2814e-02, d2: 0.0000e+00, l1_reg: 1.4887e+02, l2_reg: 6.2854e+01\n",
      "2020/09/09, 10:41:37, Iteration: 83000, Train Loss: 9.5662e-03, c1: 2.4173e-03, c2: 7.6900e-03, d1: 1.2921e-02, d2: 0.0000e+00, l1_reg: 1.4693e+02, l2_reg: 6.2578e+01\n",
      "2020/09/09, 10:42:04, Iteration: 84000, Train Loss: 9.8049e-03, c1: 2.2955e-03, c2: 1.0813e-02, d1: 1.2833e-02, d2: 0.0000e+00, l1_reg: 1.4544e+02, l2_reg: 6.2331e+01\n",
      "2020/09/09, 10:42:30, Iteration: 85000, Train Loss: 9.8515e-03, c1: 3.1103e-03, c2: 1.0554e-02, d1: 1.2836e-02, d2: 0.0000e+00, l1_reg: 1.4461e+02, l2_reg: 6.2110e+01\n",
      "2020/09/09, 10:42:56, Iteration: 86000, Train Loss: 1.0067e-02, c1: 2.0976e-03, c2: 1.3527e-02, d1: 1.2913e-02, d2: 0.0000e+00, l1_reg: 1.4295e+02, l2_reg: 6.1880e+01\n",
      "2020/09/09, 10:43:23, Iteration: 87000, Train Loss: 9.8913e-03, c1: 2.7976e-03, c2: 1.0490e-02, d1: 1.3063e-02, d2: 0.0000e+00, l1_reg: 1.4146e+02, l2_reg: 6.1651e+01\n",
      "2020/09/09, 10:43:49, Iteration: 88000, Train Loss: 9.4912e-03, c1: 2.3514e-03, c2: 7.8430e-03, d1: 1.2907e-02, d2: 0.0000e+00, l1_reg: 1.4039e+02, l2_reg: 6.1438e+01\n",
      "2020/09/09, 10:44:15, Iteration: 89000, Train Loss: 9.9491e-03, c1: 3.4192e-03, c2: 1.1711e-02, d1: 1.2871e-02, d2: 0.0000e+00, l1_reg: 1.3883e+02, l2_reg: 6.1208e+01\n",
      "2020/09/09, 10:44:42, Iteration: 90000, Train Loss: 9.9126e-03, c1: 4.2629e-03, c2: 9.3078e-03, d1: 1.3141e-02, d2: 0.0000e+00, l1_reg: 1.3755e+02, l2_reg: 6.0975e+01\n",
      "2020/09/09, 10:45:08, Iteration: 91000, Train Loss: 9.7418e-03, c1: 2.6882e-03, c2: 1.1020e-02, d1: 1.2795e-02, d2: 0.0000e+00, l1_reg: 1.3654e+02, l2_reg: 6.0806e+01\n",
      "2020/09/09, 10:45:34, Iteration: 92000, Train Loss: 9.7006e-03, c1: 2.5377e-03, c2: 1.1032e-02, d1: 1.2763e-02, d2: 0.0000e+00, l1_reg: 1.3566e+02, l2_reg: 6.0575e+01\n",
      "2020/09/09, 10:46:00, Iteration: 93000, Train Loss: 9.6780e-03, c1: 2.8900e-03, c2: 1.1432e-02, d1: 1.2582e-02, d2: 0.0000e+00, l1_reg: 1.3505e+02, l2_reg: 6.0443e+01\n",
      "2020/09/09, 10:46:27, Iteration: 94000, Train Loss: 9.5719e-03, c1: 1.6899e-03, c2: 7.9736e-03, d1: 1.3335e-02, d2: 0.0000e+00, l1_reg: 1.3356e+02, l2_reg: 6.0261e+01\n",
      "2020/09/09, 10:46:53, Iteration: 95000, Train Loss: 9.3579e-03, c1: 2.5924e-03, c2: 8.5410e-03, d1: 1.2633e-02, d2: 0.0000e+00, l1_reg: 1.3276e+02, l2_reg: 6.0073e+01\n",
      "2020/09/09, 10:47:19, Iteration: 96000, Train Loss: 9.9585e-03, c1: 1.6679e-03, c2: 1.5087e-02, d1: 1.2725e-02, d2: 0.0000e+00, l1_reg: 1.3216e+02, l2_reg: 5.9911e+01\n",
      "2020/09/09, 10:47:46, Iteration: 97000, Train Loss: 9.4735e-03, c1: 1.8523e-03, c2: 1.0837e-02, d1: 1.2589e-02, d2: 0.0000e+00, l1_reg: 1.3119e+02, l2_reg: 5.9793e+01\n",
      "2020/09/09, 10:48:12, Iteration: 98000, Train Loss: 9.2913e-03, c1: 1.7312e-03, c2: 7.7427e-03, d1: 1.2886e-02, d2: 0.0000e+00, l1_reg: 1.3050e+02, l2_reg: 5.9604e+01\n",
      "2020/09/09, 10:48:38, Iteration: 99000, Train Loss: 9.3266e-03, c1: 2.3854e-03, c2: 9.1632e-03, d1: 1.2561e-02, d2: 0.0000e+00, l1_reg: 1.2964e+02, l2_reg: 5.9482e+01\n",
      "2020/09/09, 10:49:04, Iteration: 100000, Train Loss: 9.6346e-03, c1: 3.9016e-03, c2: 1.0273e-02, d1: 1.2668e-02, d2: 0.0000e+00, l1_reg: 1.2896e+02, l2_reg: 5.9354e+01\n"
     ]
    }
   ],
   "source": [
    "config.weights = {\n",
    "\t\"c1\": 1e-1,\n",
    "\t\"c2\": 1e-1,\n",
    "\t\"d1\": 5e-1,\n",
    "\t\"d2\": 1e-1,\n",
    "\t\"l1\": 1e-5,\n",
    "\t\"l2\": 1e-5,\n",
    "}\n",
    "\n",
    "datasets = generate_dataset(config.n_data[\"i\"], config.n_data[\"b\"], config.n_data[\"cx\"], config.n_data[\"ct\"], config.n_data[\"dx\"], config.n_data[\"dt\"])\n",
    "batch_fn, evaluate_batch_fn = generate_batch_fn(config.key, config.batch_size, *datasets, config.weights)\n",
    "\n",
    "config.iterations = 50000\n",
    "agent.train(config.iterations, batch_fn, evaluate_batch_fn, config.print_every, config.save_every, config.loss_names, config.log_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:55:31, Iteration: 101000, Train Loss: 1.4347e-02, c1: 4.1542e-03, c2: 1.1034e-02, d1: 1.2972e-02, d2: 0.0000e+00, l1_reg: 1.3196e+02, l2_reg: 6.0869e+01\n",
      "2020/09/09, 10:55:56, Iteration: 102000, Train Loss: 1.3397e-02, c1: 2.7449e-03, c2: 9.4973e-03, d1: 1.2878e-02, d2: 0.0000e+00, l1_reg: 1.3209e+02, l2_reg: 6.1342e+01\n",
      "2020/09/09, 10:56:22, Iteration: 103000, Train Loss: 1.1323e-02, c1: 3.3326e-03, c2: 5.2893e-03, d1: 1.2804e-02, d2: 0.0000e+00, l1_reg: 1.3262e+02, l2_reg: 6.1672e+01\n",
      "2020/09/09, 10:56:48, Iteration: 104000, Train Loss: 1.4254e-02, c1: 5.0981e-03, c2: 1.0766e-02, d1: 1.2829e-02, d2: 0.0000e+00, l1_reg: 1.3269e+02, l2_reg: 6.1971e+01\n",
      "2020/09/09, 10:57:14, Iteration: 105000, Train Loss: 1.3806e-02, c1: 3.1828e-03, c2: 1.0236e-02, d1: 1.2846e-02, d2: 0.0000e+00, l1_reg: 1.3247e+02, l2_reg: 6.2231e+01\n",
      "2020/09/09, 10:57:41, Iteration: 106000, Train Loss: 1.2493e-02, c1: 3.7417e-03, c2: 7.5276e-03, d1: 1.2806e-02, d2: 0.0000e+00, l1_reg: 1.3276e+02, l2_reg: 6.2451e+01\n",
      "2020/09/09, 10:58:07, Iteration: 107000, Train Loss: 1.2793e-02, c1: 3.3057e-03, c2: 8.2822e-03, d1: 1.2733e-02, d2: 0.0000e+00, l1_reg: 1.3286e+02, l2_reg: 6.2679e+01\n",
      "2020/09/09, 10:58:34, Iteration: 108000, Train Loss: 1.3301e-02, c1: 3.0969e-03, c2: 9.3382e-03, d1: 1.2719e-02, d2: 0.0000e+00, l1_reg: 1.3338e+02, l2_reg: 6.2890e+01\n",
      "2020/09/09, 10:59:00, Iteration: 109000, Train Loss: 1.3064e-02, c1: 4.7791e-03, c2: 8.3172e-03, d1: 1.2946e-02, d2: 0.0000e+00, l1_reg: 1.3239e+02, l2_reg: 6.3065e+01\n",
      "2020/09/09, 10:59:27, Iteration: 110000, Train Loss: 1.2218e-02, c1: 3.4830e-03, c2: 7.0665e-03, d1: 1.2766e-02, d2: 0.0000e+00, l1_reg: 1.3212e+02, l2_reg: 6.3269e+01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray\n",
      "  return array(a, dtype, copy=False, order=order)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020/09/09, 10:59:53, Iteration: 111000, Train Loss: 1.2088e-02, c1: 3.5086e-03, c2: 6.8041e-03, d1: 1.2761e-02, d2: 0.0000e+00, l1_reg: 1.3199e+02, l2_reg: 6.3488e+01\n",
      "2020/09/09, 11:00:20, Iteration: 112000, Train Loss: 1.3564e-02, c1: 3.4118e-03, c2: 9.7360e-03, d1: 1.2801e-02, d2: 0.0000e+00, l1_reg: 1.3181e+02, l2_reg: 6.3630e+01\n",
      "2020/09/09, 11:00:46, Iteration: 113000, Train Loss: 1.2425e-02, c1: 2.8678e-03, c2: 7.6548e-03, d1: 1.2711e-02, d2: 0.0000e+00, l1_reg: 1.3176e+02, l2_reg: 6.3788e+01\n",
      "2020/09/09, 11:01:12, Iteration: 114000, Train Loss: 1.2500e-02, c1: 2.7251e-03, c2: 7.7239e-03, d1: 1.2790e-02, d2: 0.0000e+00, l1_reg: 1.3313e+02, l2_reg: 6.3969e+01\n",
      "2020/09/09, 11:01:39, Iteration: 115000, Train Loss: 1.3577e-02, c1: 3.6673e-03, c2: 9.6958e-03, d1: 1.2813e-02, d2: 0.0000e+00, l1_reg: 1.3143e+02, l2_reg: 6.4116e+01\n",
      "2020/09/09, 11:02:05, Iteration: 116000, Train Loss: 1.1329e-02, c1: 2.8335e-03, c2: 5.3735e-03, d1: 1.2810e-02, d2: 0.0000e+00, l1_reg: 1.3113e+02, l2_reg: 6.4291e+01\n",
      "2020/09/09, 11:02:31, Iteration: 117000, Train Loss: 1.1635e-02, c1: 2.9505e-03, c2: 6.0820e-03, d1: 1.2693e-02, d2: 0.0000e+00, l1_reg: 1.3077e+02, l2_reg: 6.4451e+01\n",
      "2020/09/09, 11:02:58, Iteration: 118000, Train Loss: 1.2477e-02, c1: 3.3088e-03, c2: 7.6521e-03, d1: 1.2731e-02, d2: 0.0000e+00, l1_reg: 1.3082e+02, l2_reg: 6.4625e+01\n",
      "2020/09/09, 11:03:24, Iteration: 119000, Train Loss: 1.3487e-02, c1: 3.4858e-03, c2: 9.3135e-03, d1: 1.3051e-02, d2: 0.0000e+00, l1_reg: 1.3080e+02, l2_reg: 6.4788e+01\n",
      "2020/09/09, 11:03:50, Iteration: 120000, Train Loss: 1.2541e-02, c1: 3.8435e-03, c2: 7.6006e-03, d1: 1.2800e-02, d2: 0.0000e+00, l1_reg: 1.3076e+02, l2_reg: 6.4946e+01\n",
      "2020/09/09, 11:04:17, Iteration: 121000, Train Loss: 1.2850e-02, c1: 2.8985e-03, c2: 8.1802e-03, d1: 1.3015e-02, d2: 0.0000e+00, l1_reg: 1.3113e+02, l2_reg: 6.5098e+01\n",
      "2020/09/09, 11:04:43, Iteration: 122000, Train Loss: 1.1867e-02, c1: 2.6782e-03, c2: 6.5509e-03, d1: 1.2730e-02, d2: 0.0000e+00, l1_reg: 1.3056e+02, l2_reg: 6.5256e+01\n",
      "2020/09/09, 11:05:09, Iteration: 123000, Train Loss: 1.2186e-02, c1: 3.1273e-03, c2: 7.0831e-03, d1: 1.2744e-02, d2: 0.0000e+00, l1_reg: 1.3053e+02, l2_reg: 6.5404e+01\n",
      "2020/09/09, 11:05:36, Iteration: 124000, Train Loss: 1.3156e-02, c1: 3.4502e-03, c2: 9.0243e-03, d1: 1.2673e-02, d2: 0.0000e+00, l1_reg: 1.3065e+02, l2_reg: 6.5572e+01\n",
      "2020/09/09, 11:06:02, Iteration: 125000, Train Loss: 1.1643e-02, c1: 2.7105e-03, c2: 5.8373e-03, d1: 1.2962e-02, d2: 0.0000e+00, l1_reg: 1.3147e+02, l2_reg: 6.5737e+01\n",
      "2020/09/09, 11:06:28, Iteration: 126000, Train Loss: 1.3761e-02, c1: 3.2108e-03, c2: 1.0215e-02, d1: 1.2730e-02, d2: 0.0000e+00, l1_reg: 1.3089e+02, l2_reg: 6.5892e+01\n",
      "2020/09/09, 11:06:54, Iteration: 127000, Train Loss: 1.1673e-02, c1: 4.1509e-03, c2: 5.6883e-03, d1: 1.2899e-02, d2: 0.0000e+00, l1_reg: 1.3040e+02, l2_reg: 6.6026e+01\n",
      "2020/09/09, 11:07:21, Iteration: 128000, Train Loss: 1.2381e-02, c1: 2.7976e-03, c2: 7.3291e-03, d1: 1.2942e-02, d2: 0.0000e+00, l1_reg: 1.3043e+02, l2_reg: 6.6160e+01\n",
      "2020/09/09, 11:07:47, Iteration: 129000, Train Loss: 1.2316e-02, c1: 4.0517e-03, c2: 7.1264e-03, d1: 1.2765e-02, d2: 0.0000e+00, l1_reg: 1.3021e+02, l2_reg: 6.6312e+01\n",
      "2020/09/09, 11:08:13, Iteration: 130000, Train Loss: 1.1988e-02, c1: 4.2058e-03, c2: 6.4119e-03, d1: 1.2789e-02, d2: 0.0000e+00, l1_reg: 1.3032e+02, l2_reg: 6.6397e+01\n",
      "2020/09/09, 11:08:40, Iteration: 131000, Train Loss: 1.2366e-02, c1: 3.9000e-03, c2: 7.2124e-03, d1: 1.2802e-02, d2: 0.0000e+00, l1_reg: 1.3030e+02, l2_reg: 6.6546e+01\n",
      "2020/09/09, 11:09:06, Iteration: 132000, Train Loss: 1.2970e-02, c1: 4.0483e-03, c2: 8.4406e-03, d1: 1.2756e-02, d2: 0.0000e+00, l1_reg: 1.2997e+02, l2_reg: 6.6657e+01\n",
      "2020/09/09, 11:09:33, Iteration: 133000, Train Loss: 1.3028e-02, c1: 3.1693e-03, c2: 8.6777e-03, d1: 1.2798e-02, d2: 0.0000e+00, l1_reg: 1.3058e+02, l2_reg: 6.6785e+01\n",
      "2020/09/09, 11:09:59, Iteration: 134000, Train Loss: 1.2764e-02, c1: 2.9670e-03, c2: 8.2070e-03, d1: 1.2783e-02, d2: 0.0000e+00, l1_reg: 1.3039e+02, l2_reg: 6.6895e+01\n",
      "2020/09/09, 11:10:25, Iteration: 135000, Train Loss: 1.0498e-02, c1: 2.8039e-03, c2: 3.6013e-03, d1: 1.2895e-02, d2: 0.0000e+00, l1_reg: 1.2989e+02, l2_reg: 6.7043e+01\n",
      "2020/09/09, 11:10:51, Iteration: 136000, Train Loss: 1.2462e-02, c1: 3.2765e-03, c2: 7.2543e-03, d1: 1.3080e-02, d2: 0.0000e+00, l1_reg: 1.2960e+02, l2_reg: 6.7154e+01\n",
      "2020/09/09, 11:11:18, Iteration: 137000, Train Loss: 1.2287e-02, c1: 3.3524e-03, c2: 7.1382e-03, d1: 1.2830e-02, d2: 0.0000e+00, l1_reg: 1.2945e+02, l2_reg: 6.7264e+01\n",
      "2020/09/09, 11:11:44, Iteration: 138000, Train Loss: 1.2096e-02, c1: 3.5697e-03, c2: 6.7620e-03, d1: 1.2769e-02, d2: 0.0000e+00, l1_reg: 1.2992e+02, l2_reg: 6.7390e+01\n",
      "2020/09/09, 11:12:10, Iteration: 139000, Train Loss: 1.2184e-02, c1: 3.1940e-03, c2: 6.9597e-03, d1: 1.2819e-02, d2: 0.0000e+00, l1_reg: 1.3005e+02, l2_reg: 6.7478e+01\n",
      "2020/09/09, 11:12:37, Iteration: 140000, Train Loss: 1.0730e-02, c1: 2.6848e-03, c2: 4.2459e-03, d1: 1.2728e-02, d2: 0.0000e+00, l1_reg: 1.2982e+02, l2_reg: 6.7620e+01\n",
      "2020/09/09, 11:13:03, Iteration: 141000, Train Loss: 1.1302e-02, c1: 3.7889e-03, c2: 5.0726e-03, d1: 1.2832e-02, d2: 0.0000e+00, l1_reg: 1.2936e+02, l2_reg: 6.7721e+01\n",
      "2020/09/09, 11:13:29, Iteration: 142000, Train Loss: 1.1553e-02, c1: 4.1896e-03, c2: 5.5464e-03, d1: 1.2773e-02, d2: 0.0000e+00, l1_reg: 1.2955e+02, l2_reg: 6.7833e+01\n",
      "2020/09/09, 11:13:56, Iteration: 143000, Train Loss: 1.2427e-02, c1: 3.0821e-03, c2: 7.5262e-03, d1: 1.2762e-02, d2: 0.0000e+00, l1_reg: 1.2956e+02, l2_reg: 6.7949e+01\n",
      "2020/09/09, 11:14:22, Iteration: 144000, Train Loss: 1.1392e-02, c1: 2.8696e-03, c2: 5.3578e-03, d1: 1.2883e-02, d2: 0.0000e+00, l1_reg: 1.3039e+02, l2_reg: 6.8078e+01\n",
      "2020/09/09, 11:14:48, Iteration: 145000, Train Loss: 1.1874e-02, c1: 3.1174e-03, c2: 6.3024e-03, d1: 1.2869e-02, d2: 0.0000e+00, l1_reg: 1.2950e+02, l2_reg: 6.8165e+01\n",
      "2020/09/09, 11:15:15, Iteration: 146000, Train Loss: 1.1478e-02, c1: 3.0193e-03, c2: 5.3079e-03, d1: 1.3091e-02, d2: 0.0000e+00, l1_reg: 1.2940e+02, l2_reg: 6.8290e+01\n",
      "2020/09/09, 11:15:41, Iteration: 147000, Train Loss: 1.1551e-02, c1: 2.6359e-03, c2: 5.8112e-03, d1: 1.2801e-02, d2: 0.0000e+00, l1_reg: 1.2968e+02, l2_reg: 6.8436e+01\n",
      "2020/09/09, 11:16:07, Iteration: 148000, Train Loss: 1.1709e-02, c1: 3.0030e-03, c2: 6.0231e-03, d1: 1.2808e-02, d2: 0.0000e+00, l1_reg: 1.3072e+02, l2_reg: 6.8567e+01\n",
      "2020/09/09, 11:16:33, Iteration: 149000, Train Loss: 1.2558e-02, c1: 3.5491e-03, c2: 7.6787e-03, d1: 1.2745e-02, d2: 0.0000e+00, l1_reg: 1.3038e+02, l2_reg: 6.8700e+01\n",
      "2020/09/09, 11:17:00, Iteration: 150000, Train Loss: 1.1567e-02, c1: 2.8120e-03, c2: 5.8004e-03, d1: 1.2790e-02, d2: 0.0000e+00, l1_reg: 1.3026e+02, l2_reg: 6.8835e+01\n"
     ]
    }
   ],
   "source": [
    "config.weights = {\n",
    "\t\"c1\": 1e-1,\n",
    "\t\"c2\": 5e-1,\n",
    "\t\"d1\": 5e-1,\n",
    "\t\"d2\": 1e-1,\n",
    "\t\"l1\": 1e-5,\n",
    "\t\"l2\": 1e-5,\n",
    "}\n",
    "\n",
    "datasets = generate_dataset(config.n_data[\"i\"], config.n_data[\"b\"], config.n_data[\"cx\"], config.n_data[\"ct\"], config.n_data[\"dx\"], config.n_data[\"dt\"])\n",
    "batch_fn, evaluate_batch_fn = generate_batch_fn(config.key, config.batch_size, *datasets, config.weights)\n",
    "\n",
    "config.iterations = 50000\n",
    "agent.train(config.iterations, batch_fn, evaluate_batch_fn, config.print_every, config.save_every, config.loss_names, config.log_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "/* global mpl */\n",
       "window.mpl = {};\n",
       "\n",
       "mpl.get_websocket_type = function () {\n",
       "    if (typeof WebSocket !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof MozWebSocket !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert(\n",
       "            'Your browser does not have WebSocket support. ' +\n",
       "                'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "                'Firefox 4 and 5 are also supported but you ' +\n",
       "                'have to enable WebSockets in about:config.'\n",
       "        );\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = this.ws.binaryType !== undefined;\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById('mpl-warnings');\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent =\n",
       "                'This browser does not support binary websocket messages. ' +\n",
       "                'Performance may be slow.';\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = document.createElement('div');\n",
       "    this.root.setAttribute('style', 'display: inline-block');\n",
       "    this._root_extra_style(this.root);\n",
       "\n",
       "    parent_element.appendChild(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen = function () {\n",
       "        fig.send_message('supports_binary', { value: fig.supports_binary });\n",
       "        fig.send_message('send_image_mode', {});\n",
       "        if (mpl.ratio !== 1) {\n",
       "            fig.send_message('set_dpi_ratio', { dpi_ratio: mpl.ratio });\n",
       "        }\n",
       "        fig.send_message('refresh', {});\n",
       "    };\n",
       "\n",
       "    this.imageObj.onload = function () {\n",
       "        if (fig.image_mode === 'full') {\n",
       "            // Full images could contain transparency (where diff images\n",
       "            // almost always do), so we need to clear the canvas so that\n",
       "            // there is no ghosting.\n",
       "            fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "        }\n",
       "        fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "    };\n",
       "\n",
       "    this.imageObj.onunload = function () {\n",
       "        fig.ws.close();\n",
       "    };\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._init_header = function () {\n",
       "    var titlebar = document.createElement('div');\n",
       "    titlebar.classList =\n",
       "        'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n",
       "    var titletext = document.createElement('div');\n",
       "    titletext.classList = 'ui-dialog-title';\n",
       "    titletext.setAttribute(\n",
       "        'style',\n",
       "        'width: 100%; text-align: center; padding: 3px;'\n",
       "    );\n",
       "    titlebar.appendChild(titletext);\n",
       "    this.root.appendChild(titlebar);\n",
       "    this.header = titletext;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function () {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = (this.canvas_div = document.createElement('div'));\n",
       "    canvas_div.setAttribute(\n",
       "        'style',\n",
       "        'border: 1px solid #ddd;' +\n",
       "            'box-sizing: content-box;' +\n",
       "            'clear: both;' +\n",
       "            'min-height: 1px;' +\n",
       "            'min-width: 1px;' +\n",
       "            'outline: 0;' +\n",
       "            'overflow: hidden;' +\n",
       "            'position: relative;' +\n",
       "            'resize: both;'\n",
       "    );\n",
       "\n",
       "    function on_keyboard_event_closure(name) {\n",
       "        return function (event) {\n",
       "            return fig.key_event(event, name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    canvas_div.addEventListener(\n",
       "        'keydown',\n",
       "        on_keyboard_event_closure('key_press')\n",
       "    );\n",
       "    canvas_div.addEventListener(\n",
       "        'keyup',\n",
       "        on_keyboard_event_closure('key_release')\n",
       "    );\n",
       "\n",
       "    this._canvas_extra_style(canvas_div);\n",
       "    this.root.appendChild(canvas_div);\n",
       "\n",
       "    var canvas = (this.canvas = document.createElement('canvas'));\n",
       "    canvas.classList.add('mpl-canvas');\n",
       "    canvas.setAttribute('style', 'box-sizing: content-box;');\n",
       "\n",
       "    this.context = canvas.getContext('2d');\n",
       "\n",
       "    var backingStore =\n",
       "        this.context.backingStorePixelRatio ||\n",
       "        this.context.webkitBackingStorePixelRatio ||\n",
       "        this.context.mozBackingStorePixelRatio ||\n",
       "        this.context.msBackingStorePixelRatio ||\n",
       "        this.context.oBackingStorePixelRatio ||\n",
       "        this.context.backingStorePixelRatio ||\n",
       "        1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n",
       "        'canvas'\n",
       "    ));\n",
       "    rubberband_canvas.setAttribute(\n",
       "        'style',\n",
       "        'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n",
       "    );\n",
       "\n",
       "    var resizeObserver = new ResizeObserver(function (entries) {\n",
       "        var nentries = entries.length;\n",
       "        for (var i = 0; i < nentries; i++) {\n",
       "            var entry = entries[i];\n",
       "            var width, height;\n",
       "            if (entry.contentBoxSize) {\n",
       "                width = entry.contentBoxSize.inlineSize;\n",
       "                height = entry.contentBoxSize.blockSize;\n",
       "            } else {\n",
       "                width = entry.contentRect.width;\n",
       "                height = entry.contentRect.height;\n",
       "            }\n",
       "\n",
       "            // Keep the size of the canvas and rubber band canvas in sync with\n",
       "            // the canvas container.\n",
       "            canvas.setAttribute('width', width * mpl.ratio);\n",
       "            canvas.setAttribute('height', height * mpl.ratio);\n",
       "            canvas.setAttribute(\n",
       "                'style',\n",
       "                'width: ' + width + 'px; height: ' + height + 'px;'\n",
       "            );\n",
       "\n",
       "            rubberband_canvas.setAttribute('width', width);\n",
       "            rubberband_canvas.setAttribute('height', height);\n",
       "\n",
       "            // And update the size in Python. We ignore the initial 0/0 size\n",
       "            // that occurs as the element is placed into the DOM, which should\n",
       "            // otherwise not happen due to the minimum size styling.\n",
       "            if (width != 0 && height != 0) {\n",
       "                fig.request_resize(width, height);\n",
       "            }\n",
       "        }\n",
       "    });\n",
       "    resizeObserver.observe(canvas_div);\n",
       "\n",
       "    function on_mouse_event_closure(name) {\n",
       "        return function (event) {\n",
       "            return fig.mouse_event(event, name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mousedown',\n",
       "        on_mouse_event_closure('button_press')\n",
       "    );\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseup',\n",
       "        on_mouse_event_closure('button_release')\n",
       "    );\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mousemove',\n",
       "        on_mouse_event_closure('motion_notify')\n",
       "    );\n",
       "\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseenter',\n",
       "        on_mouse_event_closure('figure_enter')\n",
       "    );\n",
       "    rubberband_canvas.addEventListener(\n",
       "        'mouseleave',\n",
       "        on_mouse_event_closure('figure_leave')\n",
       "    );\n",
       "\n",
       "    canvas_div.addEventListener('wheel', function (event) {\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        on_mouse_event_closure('scroll')(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.appendChild(canvas);\n",
       "    canvas_div.appendChild(rubberband_canvas);\n",
       "\n",
       "    this.rubberband_context = rubberband_canvas.getContext('2d');\n",
       "    this.rubberband_context.strokeStyle = '#000000';\n",
       "\n",
       "    this._resize_canvas = function (width, height, forward) {\n",
       "        if (forward) {\n",
       "            canvas_div.style.width = width + 'px';\n",
       "            canvas_div.style.height = height + 'px';\n",
       "        }\n",
       "    };\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus() {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function () {\n",
       "    var fig = this;\n",
       "\n",
       "    var toolbar = document.createElement('div');\n",
       "    toolbar.classList = 'mpl-toolbar';\n",
       "    this.root.appendChild(toolbar);\n",
       "\n",
       "    function on_click_closure(name) {\n",
       "        return function (_event) {\n",
       "            return fig.toolbar_button_onclick(name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    function on_mouseover_closure(tooltip) {\n",
       "        return function (event) {\n",
       "            if (!event.currentTarget.disabled) {\n",
       "                return fig.toolbar_button_onmouseover(tooltip);\n",
       "            }\n",
       "        };\n",
       "    }\n",
       "\n",
       "    fig.buttons = {};\n",
       "    var buttonGroup = document.createElement('div');\n",
       "    buttonGroup.classList = 'mpl-button-group';\n",
       "    for (var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            /* Instead of a spacer, we start a new button group. */\n",
       "            if (buttonGroup.hasChildNodes()) {\n",
       "                toolbar.appendChild(buttonGroup);\n",
       "            }\n",
       "            buttonGroup = document.createElement('div');\n",
       "            buttonGroup.classList = 'mpl-button-group';\n",
       "            continue;\n",
       "        }\n",
       "\n",
       "        var button = (fig.buttons[name] = document.createElement('button'));\n",
       "        button.classList = 'mpl-widget';\n",
       "        button.setAttribute('role', 'button');\n",
       "        button.setAttribute('aria-disabled', 'false');\n",
       "        button.addEventListener('click', on_click_closure(method_name));\n",
       "        button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
       "\n",
       "        var icon_img = document.createElement('img');\n",
       "        icon_img.src = '_images/' + image + '.png';\n",
       "        icon_img.srcset = '_images/' + image + '_large.png 2x';\n",
       "        icon_img.alt = tooltip;\n",
       "        button.appendChild(icon_img);\n",
       "\n",
       "        buttonGroup.appendChild(button);\n",
       "    }\n",
       "\n",
       "    if (buttonGroup.hasChildNodes()) {\n",
       "        toolbar.appendChild(buttonGroup);\n",
       "    }\n",
       "\n",
       "    var fmt_picker = document.createElement('select');\n",
       "    fmt_picker.classList = 'mpl-widget';\n",
       "    toolbar.appendChild(fmt_picker);\n",
       "    this.format_dropdown = fmt_picker;\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = document.createElement('option');\n",
       "        option.selected = fmt === mpl.default_extension;\n",
       "        option.innerHTML = fmt;\n",
       "        fmt_picker.appendChild(option);\n",
       "    }\n",
       "\n",
       "    var status_bar = document.createElement('span');\n",
       "    status_bar.classList = 'mpl-message';\n",
       "    toolbar.appendChild(status_bar);\n",
       "    this.message = status_bar;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', { width: x_pixels, height: y_pixels });\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.send_message = function (type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function () {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function (fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1], msg['forward']);\n",
       "        fig.send_message('refresh', {});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0,\n",
       "        0,\n",
       "        fig.canvas.width / mpl.ratio,\n",
       "        fig.canvas.height / mpl.ratio\n",
       "    );\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch (cursor) {\n",
       "        case 0:\n",
       "            cursor = 'pointer';\n",
       "            break;\n",
       "        case 1:\n",
       "            cursor = 'default';\n",
       "            break;\n",
       "        case 2:\n",
       "            cursor = 'crosshair';\n",
       "            break;\n",
       "        case 3:\n",
       "            cursor = 'move';\n",
       "            break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_message = function (fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n",
       "    for (var key in msg) {\n",
       "        if (!(key in fig.buttons)) {\n",
       "            continue;\n",
       "        }\n",
       "        fig.buttons[key].disabled = !msg[key];\n",
       "        fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n",
       "    if (msg['mode'] === 'PAN') {\n",
       "        fig.buttons['Pan'].classList.add('active');\n",
       "        fig.buttons['Zoom'].classList.remove('active');\n",
       "    } else if (msg['mode'] === 'ZOOM') {\n",
       "        fig.buttons['Pan'].classList.remove('active');\n",
       "        fig.buttons['Zoom'].classList.add('active');\n",
       "    } else {\n",
       "        fig.buttons['Pan'].classList.remove('active');\n",
       "        fig.buttons['Zoom'].classList.remove('active');\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function () {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message('ack', {});\n",
       "};\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function (fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = 'image/png';\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src\n",
       "                );\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data\n",
       "            );\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        } else if (\n",
       "            typeof evt.data === 'string' &&\n",
       "            evt.data.slice(0, 21) === 'data:image/png;base64'\n",
       "        ) {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig['handle_' + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\n",
       "                \"No handler for the '\" + msg_type + \"' message type: \",\n",
       "                msg\n",
       "            );\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\n",
       "                    \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n",
       "                    e,\n",
       "                    e.stack,\n",
       "                    msg\n",
       "                );\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "};\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function (e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e) {\n",
       "        e = window.event;\n",
       "    }\n",
       "    if (e.target) {\n",
       "        targ = e.target;\n",
       "    } else if (e.srcElement) {\n",
       "        targ = e.srcElement;\n",
       "    }\n",
       "    if (targ.nodeType === 3) {\n",
       "        // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "    }\n",
       "\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    var boundingRect = targ.getBoundingClientRect();\n",
       "    var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n",
       "    var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n",
       "\n",
       "    return { x: x, y: y };\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys(original) {\n",
       "    return Object.keys(original).reduce(function (obj, key) {\n",
       "        if (typeof original[key] !== 'object') {\n",
       "            obj[key] = original[key];\n",
       "        }\n",
       "        return obj;\n",
       "    }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function (event, name) {\n",
       "    var canvas_pos = mpl.findpos(event);\n",
       "\n",
       "    if (name === 'button_press') {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {\n",
       "        x: x,\n",
       "        y: y,\n",
       "        button: event.button,\n",
       "        step: event.step,\n",
       "        guiEvent: simpleKeys(event),\n",
       "    });\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.key_event = function (event, name) {\n",
       "    // Prevent repeat events\n",
       "    if (name === 'key_press') {\n",
       "        if (event.which === this._key) {\n",
       "            return;\n",
       "        } else {\n",
       "            this._key = event.which;\n",
       "        }\n",
       "    }\n",
       "    if (name === 'key_release') {\n",
       "        this._key = null;\n",
       "    }\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which !== 17) {\n",
       "        value += 'ctrl+';\n",
       "    }\n",
       "    if (event.altKey && event.which !== 18) {\n",
       "        value += 'alt+';\n",
       "    }\n",
       "    if (event.shiftKey && event.which !== 16) {\n",
       "        value += 'shift+';\n",
       "    }\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n",
       "    return false;\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n",
       "    if (name === 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message('toolbar_button', { name: name });\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
       "\n",
       "mpl.default_extension = \"png\";/* global mpl */\n",
       "\n",
       "var comm_websocket_adapter = function (comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function () {\n",
       "        comm.close();\n",
       "    };\n",
       "    ws.send = function (m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function (msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overridden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data']);\n",
       "    });\n",
       "    return ws;\n",
       "};\n",
       "\n",
       "mpl.mpl_figure_comm = function (comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = document.getElementById(id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm);\n",
       "\n",
       "    function ondownload(figure, _format) {\n",
       "        window.open(figure.canvas.toDataURL());\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element;\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error('Failed to find cell for figure', id, fig);\n",
       "        return;\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function (fig, msg) {\n",
       "    var width = fig.canvas.width / mpl.ratio;\n",
       "    fig.root.removeEventListener('remove', this._remove_fig_handler);\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable();\n",
       "    fig.parent_element.innerHTML =\n",
       "        '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "    fig.close_ws(fig, msg);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.close_ws = function (fig, msg) {\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width / mpl.ratio;\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] =\n",
       "        '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function () {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message('ack', {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () {\n",
       "        fig.push_to_output();\n",
       "    }, 1000);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function () {\n",
       "    var fig = this;\n",
       "\n",
       "    var toolbar = document.createElement('div');\n",
       "    toolbar.classList = 'btn-toolbar';\n",
       "    this.root.appendChild(toolbar);\n",
       "\n",
       "    function on_click_closure(name) {\n",
       "        return function (_event) {\n",
       "            return fig.toolbar_button_onclick(name);\n",
       "        };\n",
       "    }\n",
       "\n",
       "    function on_mouseover_closure(tooltip) {\n",
       "        return function (event) {\n",
       "            if (!event.currentTarget.disabled) {\n",
       "                return fig.toolbar_button_onmouseover(tooltip);\n",
       "            }\n",
       "        };\n",
       "    }\n",
       "\n",
       "    fig.buttons = {};\n",
       "    var buttonGroup = document.createElement('div');\n",
       "    buttonGroup.classList = 'btn-group';\n",
       "    var button;\n",
       "    for (var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            /* Instead of a spacer, we start a new button group. */\n",
       "            if (buttonGroup.hasChildNodes()) {\n",
       "                toolbar.appendChild(buttonGroup);\n",
       "            }\n",
       "            buttonGroup = document.createElement('div');\n",
       "            buttonGroup.classList = 'btn-group';\n",
       "            continue;\n",
       "        }\n",
       "\n",
       "        button = fig.buttons[name] = document.createElement('button');\n",
       "        button.classList = 'btn btn-default';\n",
       "        button.href = '#';\n",
       "        button.title = name;\n",
       "        button.innerHTML = '<i class=\"fa ' + image + ' fa-lg\"></i>';\n",
       "        button.addEventListener('click', on_click_closure(method_name));\n",
       "        button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n",
       "        buttonGroup.appendChild(button);\n",
       "    }\n",
       "\n",
       "    if (buttonGroup.hasChildNodes()) {\n",
       "        toolbar.appendChild(buttonGroup);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = document.createElement('span');\n",
       "    status_bar.classList = 'mpl-message pull-right';\n",
       "    toolbar.appendChild(status_bar);\n",
       "    this.message = status_bar;\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = document.createElement('div');\n",
       "    buttongrp.classList = 'btn-group inline pull-right';\n",
       "    button = document.createElement('button');\n",
       "    button.classList = 'btn btn-mini btn-primary';\n",
       "    button.href = '#';\n",
       "    button.title = 'Stop Interaction';\n",
       "    button.innerHTML = '<i class=\"fa fa-power-off icon-remove icon-large\"></i>';\n",
       "    button.addEventListener('click', function (_evt) {\n",
       "        fig.handle_close(fig, {});\n",
       "    });\n",
       "    button.addEventListener(\n",
       "        'mouseover',\n",
       "        on_mouseover_closure('Stop Interaction')\n",
       "    );\n",
       "    buttongrp.appendChild(button);\n",
       "    var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n",
       "    titlebar.insertBefore(buttongrp, titlebar.firstChild);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._remove_fig_handler = function () {\n",
       "    this.close_ws(this, {});\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function (el) {\n",
       "    el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n",
       "    el.addEventListener('remove', this._remove_fig_handler);\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function (el) {\n",
       "    // this is important to make the div 'focusable\n",
       "    el.setAttribute('tabindex', 0);\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    } else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function (event, _name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager) {\n",
       "        manager = IPython.keyboard_manager;\n",
       "    }\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which === 13) {\n",
       "        this.canvas_div.blur();\n",
       "        // select the cell after this one\n",
       "        var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n",
       "        IPython.notebook.select(index + 1);\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_save = function (fig, _msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "};\n",
       "\n",
       "mpl.find_output_cell = function (html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i = 0; i < ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code') {\n",
       "            for (var j = 0; j < cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] === html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "};\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel !== null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target(\n",
       "        'matplotlib',\n",
       "        mpl.mpl_figure_comm\n",
       "    );\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"1499.6833333333334\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from loss import inverse_model, direct_model\n",
    "from data import domain\n",
    "import jax.numpy as jnp\n",
    "import numpy as np\n",
    "\n",
    "inverse_params = agent.params[1]\n",
    "x_test = jnp.linspace(*domain[:, 0], 100).reshape((-1, 1))\n",
    "a_fn = lambda x: 1+2/np.pi*np.cos(2*np.pi*x)\n",
    "a_pred = inverse_model(inverse_params, x_test)\n",
    "a_true = a_fn(x_test)\n",
    "\n",
    "direct_params = agent.params[0]\n",
    "t_test = domain[1, 1]*jnp.ones_like(x_test)\n",
    "uv_pred = direct_model(direct_params, jnp.hstack([x_test, t_test]))\n",
    "\n",
    "from scipy.io import loadmat\n",
    "data_true = loadmat(\"problem2_2_snapshot_epsilon_1e-12.mat\")\n",
    "u_true, v_true = data_true[\"u_snapshots\"][:, -1], data_true[\"v_snapshots\"][:, -1]\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib notebook\n",
    "\n",
    "f, ax = plt.subplots(1, 3, figsize = (15, 5))\n",
    "ax[0].plot(x_test, a_pred, label = \"pred\")\n",
    "ax[0].plot(x_test, a_true, label = \"true\")\n",
    "ax[0].set_title(\"a\")\n",
    "ax[1].plot(x_test, uv_pred[:, 0:1], label = \"pred\")\n",
    "ax[1].plot(x_test, u_true, label = \"true\")\n",
    "ax[1].set_title(\"u\")\n",
    "ax[2].plot(x_test, uv_pred[:, 1:2], label = \"pred\")\n",
    "ax[2].plot(x_test, v_true, label = \"true\")\n",
    "ax[2].set_title(\"v\")\n",
    "for ax_ in ax:\n",
    "\tax_.legend()\n",
    "\tax_.grid()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DeviceArray([-3.004625], dtype=float32)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.params[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(agent.params[1].shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
